<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>index</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="./css/common.css">
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			
			.home_icon {
				width: 20px;
			}
			
			.mui-bar-tab .mui-tab-item.mui-active {
				color: #0082E6;
			}
			
			.mui-bar-tab {
				height: 53px;
				padding-top: 3px;
			}
      .footer{
        position: fixed;
        width: 100%;
        z-index: 9999;
       height: 53px;
       
        line-height: 53px;
        background-color: #fff;
        bottom: 0;
        padding: 0;
        padding-top: 3px;
        text-align: center;
      }
		</style>
	</head>

	<body>
		
		<!--<header class="mui-bar mui-bar-nav">
			<h1 id="title" class="mui-title">首页</h1>
		</header>-->
		<nav class="mui-bar mui-bar-tab" style="background-color:#f7f7f7;">
			<a id="defaultTab" class="mui-tab-item mui-active" data="./group/index.html">
				<span class="mui-icon ">
					<img src="img/home0_.png" class="home_icon"/>
				</span>
				<span class="mui-tab-label">首页</span>
			</a>
			<!--
			<a id="defaultTab1" class="mui-tab-item" data="./home/work.html">
				<span class="mui-icon ">
					<img src="img/home1.png" class="home_icon"/>
				</span>
				<span class="mui-tab-label">工作台</span>
			</a>
			<a id="defaultTab2" class="mui-tab-item" data="./home/application.html">
				<span class="mui-icon ">
					<img src="img/home2.png" class="home_icon"/>
					
				</span>
				<span class="mui-tab-label">应用</span>
			</a>
			<a id="defaultTab3" class="mui-tab-item" data="./home/message.html">
				<span class="mui-icon ">
					<img src="img/home3.png" class="home_icon"/>
					
				</span>
				<span class="mui-tab-label">消息</span>
			</a>
			-->
			<a id="workbench" class="mui-tab-item" data="../sitOperation/terminalwork/terminalwork.html"
			style="display:none;">
				<span class="mui-icon ">
					<img src="img/home1.png" class="home_icon"/>
				</span>
				<span class="mui-tab-label">工作台</span>
			</a>
			<a id="saoma" class="mui-tab-item" data="../sitOperation/scan.html" >
				<span class="mui-icon ">
					<img src="img/home5.png" class="home_icon"/>
				</span>
				<span class="mui-tab-label">扫一扫</span>
			</a>
			<a id="message" class="mui-tab-item" data="../sitOperation/notice/notice.html" >
				<span class="mui-icon ">
					<img src="img/home3.png" class="home_icon"/> 
				</span>
				<span class="mui-tab-label">消息</span>
			</a>
			<a id="defaultTab4" class="mui-tab-item" data="./group/usercenter.html">
				<span class="mui-icon">
					<img src="img/home4.png" class="home_icon"/>
					
				</span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>
		<script src="../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../js/jquery-3.2.1.min.js"></script>
		<script type="text/javascript" src="../../js/vue.js"></script>
		<script src="js/mkeyplus.base.js"></script>
		<script src="../sitOperation/static/js/neiosRequst.js"></script>
		<script src="../sitOperation/static/js/neiosCommon.js"></script>
		<script type="text/javascript" charset="utf-8">
//		localStorage.clear();
      var home = null;
			var network;
      var page;
			//mui初始化
			mui.init();
			mui.plusReady(function() {
       //弹起软键盘时挤压页面
       var height = document.documentElement.clientHeight || document.body.clientHeight;
        plus.webview.currentWebview().setStyle({
            height: height
        });
        window.onresize = function() {
            plus.webview.currentWebview().setStyle({
                height: height
            })
        }
			});
      
			var subpages = ['./group/index.html','../sitOperation/terminalwork/terminalwork.html',
			'../sitOperation/scan.html',
			'../sitOperation/notice/notice.html', './group/usercenter.html'];

			var subpage_style = {
				top: '0px',
				bottom: '51px'
			};
			var aniShow = {};
			if(window.plus) {
				plusready();
			} else {
				document.addEventListener('plusready', plusready, false);
			}
			var activeTab;

			function plusready() {
				var self = plus.webview.currentWebview();
				network = self.network;
				for(var i = 0; i < subpages.length; i++) {
					var temp = {};
					var sub = plus.webview.create(subpages[i], subpages[i], subpage_style,{network:network});
					console.log("窗口ID:" + sub.id);
					if(i != 0) {
						console.log("隐藏的窗口:" + sub.id);
						sub.hide();
					} else {
						temp[subpages[0]] = "true";
						mui.extend(aniShow, temp);
					}
					self.append(sub);
				}

				//默认当前激活选项 ，以及id

				activeTab = subpages[0];
				var defaultt = "./group/index.html";
				mui(".mui-bar-tab").on("tap", "a", function() {
					var targetTab = this.getAttribute('data');
					var defaultt = this.getAttribute("id");
					let strId = defaultt+"";
					console.log("当前点击按钮" + targetTab + defaultt);
					if(targetTab == activeTab) {
						return;
					}
					//判断是否登录成功 defaultt
					let isUser = localStorage.getItem('neiosUser')//pages/neom/formal/login_ext.html
					console.log(isUser+":LLLLLLLLLL:"+defaultt+":"+(isUser == "获取用户信息失败"))
					if(isUser == "获取用户信息失败" && defaultt == "saoma"){
						mui.confirm("扫一扫功属于智能运维系统，需要重新登录",'提示',['确认'],function (e) {
							if(0 == e.index){
								mui.openWindow({
									url: 'formal/login_ext.html',
									id: 'home.html',
									show:{
										aniShow:'none' 
									} 
								});
								
								setTimeout(function(){
									plus.webview.currentWebview().close();
								},1000);
								
							}
						});
						
						return;
					}
					if(mui.os.ios || aniShow[targetTab]) {
						console.log("第二次打开了===" + targetTab);
						//					if(targetTab == "shouye1.html"){
						//						plus.webview.getWebviewById("shouye1.html").evalJS("refreshhome()");
						//					}
						if ( targetTab == '../sitOperation/terminalwork/terminalwork.html') {
							let page = plus.webview.getWebviewById("../sitOperation/terminalwork/terminalwork.html");  
							let pageId = plus.webview.getWebviewById(page.id); 
							let param = {} 
							param.isRefresh = true
							mui.fire(pageId, 'isRefresh', param);
						}
						plus.webview.show(targetTab, "fade-in", 0);
					} else {
						//否则，使用fade-in动画，且保存变量
						console.log("else===" + targetTab);
						//					if(targetTab == "shouye1.html"){
						//						plus.webview.getWebviewById("shouye1.html").evalJS("refreshhome()");
						//					}
						var temp = {};
						temp[targetTab] = "true";
						mui.extend(aniShow, temp);
						if ( targetTab == '../sitOperation/terminalwork/terminalwork.html') {
							let page = plus.webview.getWebviewById("../sitOperation/terminalwork/terminalwork.html");  
							let pageId = plus.webview.getWebviewById(page.id); 
							let param = {} 
							param.isRefresh = true
							mui.fire(pageId, 'isRefresh', param);
						}
						plus.webview.show(targetTab, "fade-in", 0);
					}

					console.log("隐藏的页面：" + activeTab);
					//隐藏当前;
					plus.webview.hide(activeTab);
					//plus.webview.show(targetTab);
					//更改当前活跃的选项卡
					activeTab = targetTab;
				});
				
				mui.trigger(document.getElementById("defaultTab"), 'tap');
			}
			//		mui.back = function(){			
			//			var main = plus.android.runtimeMainActivity();
			// 			main.moveTaskToBack(false);
			//		}
			mui(".mui-bar-tab a").each(function(i, btn) {
				btn.addEventListener('tap', function() {
					for(var j = 0; j < 5; j++) {
						var imgnum = j ;
						var imgstr = "img/home" + imgnum + ".png";
						$(".home_icon").eq(j).attr("src", imgstr);
					}
					var thisimgnum = i;
					$(this).find(".home_icon").attr("src", "img/home" + thisimgnum + "_.png");
					//bottom-icon2-.png
				}, false);
			});
      //自定义事件，模拟点击“首页选项卡”
      document.addEventListener('gohome', function() {
      	var defaultTab = document.getElementById("defaultTab");
      	//模拟首页点击
        console.log(defaultTab)
      	mui.trigger(defaultTab, 'tap');
      	//切换选项卡高亮
      	var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
      	if (defaultTab !== current) {
      		current.classList.remove('mui-active');
      		defaultTab.classList.add('mui-active');
      	}
      });
			// var old_back = mui.back;
			// mui.back = function(){  
			//     //显示上一个界面；  
			//    var self = plus.webview.currentWebview();
			//    var opener = self.opener(); 
			//    old_back();  
			// }
      
      
      
   //   // 监听返回
   //    document.addEventListener('back', function(event) {  
   //       old_back()
   //    });
		
		// 获取人员信息
		let userInfo = JSON.parse(localStorage.getItem('neiosUser'))
		console.log("人员信息:"+localStorage.getItem('neiosUser'))
		if (userInfo.isNewPerson) { 
			$('#workbench').show() // 显示工作台  
			// 判断是否有场站权限
			console.log("AA"+userInfo.roles.indexOf('NEIOS_STATION'))
			if (userInfo.roles.indexOf('NEIOS_STATION') > -1) { // 如果当前登陆人的权限是场站，正常显示
				if (userInfo.stationNewCode == null || userInfo.stationNewCode == '' || userInfo.stationNewCode == undefined) {
					mui.toast('您没有场站权限,请联系管理员配置!') 
					$('#workbench').show()
				} else {
					localStorage.setItem('neiosStationName',userInfo.stationNewNames[0])
					localStorage.setItem('neiosStationCode',userInfo.stationNewCodes[0])
				}
			}
		}
		</script> 
	</body>  

</html>